package com.gangan.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gangan.model.Auth;
import com.gangan.mapper.AuthMapper;
import com.gangan.model.Role;
import com.gangan.model.search.AuthSearch;
import com.gangan.model.view.AuthView;
import com.gangan.service.IAuthService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gangan.service.IRoleService;
import com.gangan.tools.StringTools;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-08-20
 */
@Service
public class AuthServiceImpl extends ServiceImpl<AuthMapper, Auth> implements IAuthService {

    @Autowired
    AuthMapper mapper;

    @Autowired
    IRoleService roleService;

    /**
     * 根据角色id查询该角色的权限以及菜单
     * @return
     */
    @Override
    public List<Auth> resultAuthByRoleId(Integer roleId) {
        Role role = roleService.getById(roleId);
        if(null== role || StringUtils.isBlank(role.getRoleAuthIds())){
            return new ArrayList<>();
        }
        return this.list(Wrappers.<Auth>query()
                .lambda().in(Auth::getAuthId, StringTools.resultIntegerArrayBySplitString(role.getRoleAuthIds())));
    }

}
